#ifndef _csArchiveSystem_h_
#define _csArchiveSystem_h_

/********************************************************************
	created:	2009/11/06
	created:	6:11:2009   14:40
	filename: 	e:\csEngine\csCoreLib\src\io\csArchiveSystem.h
	file path:	e:\csEngine\csCoreLib\src\io
	file base:	csArchiveSystem
	file ext:	h
	author:		dongchengok
	
	purpose:	
*********************************************************************/
#include "csType.h"
#include "csString.h"
#include "csArray.h"
#include "csHashMap.h"
#include "csIArchive.h"

//------------------------------------------------------------------------
class csArchiveSystem
{
	typedef csHashMap<csString,csIArchive*>	csMountedArchives;
public:
	csArchiveSystem();
	~csArchiveSystem();

	//gloabe function
	static bool					SetSystemWorkingDir(const csString& path);
	static csString				ConcatenatePath(const csString& base, const csString& path);
	static csString				GetAbsolutePath(const csString& path);
	static csString				GetFileName(const csString& path);
	static bool					IsFileExist(const csString& path);
	static bool					IsAbsolutePath(const csString& path);
	static bool					IsArchivePath(const csString& path);
	static bool					IsReverseDir(const csString& path);
	static bool					IsCaseSensitive();
	static csStream*			OpenAbsoluteStream(const csString& path, csEStreamAccessType type);
	static void					SaveAbsoluteStream(const csString& path, csStream& stream);

	//set this archive working dictionary
	void						setWorkingDir(const csString& path);
	const csString&				getWorkingDir() const;

	csArray<const csIArchive*>	findMountedArchiveByPath(const csString& path) const;
	const csIArchive*			findMountedArchiveByUrl(const csString& url) const;

	//fuck open the file in the archive system
	csStream*					open(const csString& path, csEStreamAccessType type=csESAT_WRITE);
	void						save(const csString& path, csStream& stream);

	//url like device c,for example we can mount a archive d:\abc with fuck,and wo access
	//d:\abc\haha\fuck.c with fuck:\haha\fuck.c
	//url can not have \,/,.,: and length more than 1
	bool						mount(const csString& url, const csString& archive, csEArchiveType type=csEAT_FILE);
	void						unmount(const csString& url);

	csArray<csString>			listMountedArchivesUrl() const;

protected:
	bool						_urlValid(const csString& url) const;
	csIArchive*					_createFileArchive(const csString& path) const;
	csIArchive*					_createZipArchive(const csString& path) const;

protected:
	csString					m_workingDictionary;
	csMountedArchives			m_mountedArchives;
};

//------------------------------------------------------------------------
csINLINE void
csArchiveSystem::setWorkingDir(const csString& path)
{
	m_workingDictionary	= path;
}

//------------------------------------------------------------------------
csINLINE const csString&
csArchiveSystem::getWorkingDir() const
{
	return m_workingDictionary;
}

#endif // _csArchiveSystem_h_